package jtk.project4.fleet.screen.addscheduleRepair;

/* 
 * Author               : Ezhar Ferbi Subyadi
 * Date Created         : 4-April-2011 
 * Date Modified        : 6-April-2011 
 * Version              : 1.1 
 * */ 

import java.awt.Button;
import java.awt.FlowLayout;


import jtk.project4.fleet.field.AddScheduledRepairField;
import jtk.project4.fleet.field.IdentificationField;

import nl.coderight.jazz.action.Action;
import nl.coderight.jazz.dialog.MessageType;
import nl.coderight.jazz.dialog.OptionDialog;
import nl.coderight.jazz.dialog.OptionType;
import nl.coderight.jazz.dialog.ReturnOptionType;
import nl.coderight.jazz.form.FormHeader;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.field.button.PushButton;

public class ScheduleRepairView extends FormView{
	private FormHeader formHeader;
	private PushButton submitButton;
	private PushButton cancelButton;
	private Action submitAction;
	private Action cancelAction;
	@Override
	public void close() {
		// check if form is changed, if true show dialog
		if (isChanged()) {
			OptionDialog dialog = new OptionDialog(this);
			dialog.setMessageType(MessageType.QUESTION);
			dialog.setTitle("dialog.discard.title");
			dialog.setMessage("dialog.discard.message");
			dialog.setOptionType(OptionType.YES_NO);
			dialog.setOptions("button.yes", "button.no", "");
			dialog.show();
			if (dialog.getReturnOptionType() == ReturnOptionType.NO) {
				focus();
				return;
			}
		}
		super.close();
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		//createAction();
		createFields();
		createLayout();	
	}
	
	/**private void createAction()
	{
		submitAction = new SubmitAction();
		cancelAction = new CancelAction();
		// enable submit button when form is changed
		setOnChangeAction(submitAction);	
	}*/
	
	private void createFields(){
		submitButton = new PushButton("Save");
		cancelButton = new PushButton("Cancel");
	}
	private void createLayout() {
		setHeader(createHeader());
		addField(createForm());
	}
	
	private FormHeader createHeader() {
		formHeader = new FormHeader();
		formHeader.setTitle("Schedule Repair.header.form");
		return formHeader;
	}
	private GroupControl<String> createButtons() {
		GroupControl<String> buttons = new GroupControl<String>();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(submitButton);
		buttons.addField(cancelButton);
		return buttons;
	}
	
	private GroupControl createForm() {
		GroupControl form = new GroupControl();
		form.addField(new AddScheduledRepairField("Identification"), NORTH);
		form.addField(createButtons(), SOUTH);		
		return form;
	}

	
}
